package com.guyou.guguxinge;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.cbs.android.component.application.activity.CBSActivity;
import com.cbs.android.component.application.activity.handler.CBSSimpleActivityResultHandler;
import com.cbs.android.component.toast.Toast;
import com.cbs.android.module.user.user.UserModule;
import com.cbs.android.module.user.user.entity.User;
import com.cbs.android.module.user.user.handler.ModuleHandler;
import com.cbs.android.module.userkit.UserKit;

public class MainActivity extends CBSActivity {
    private static final String TAG = MainActivity.class.getName();
    private CBSSimpleActivityResultHandler handler = new CBSSimpleActivityResultHandler() {
        @Override
        public void onSuccess(int i, Intent intent) {
            Toast.show("成功");
        }

        @Override
        public void onCancel(int i, Intent intent) {
            if (intent!=null && intent.hasExtra(UserKit.IntentMessage)) {
                Toast.show(intent.getStringExtra(UserKit.IntentMessage));
            } else {
                Toast.show("取消");
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void logout(View view) {
        UserModule.logout(new ModuleHandler<User>() {
            @Override
            public void onSuccess(User user) {
                Toast.show("退出登录成功");
            }

            @Override
            public void onFailure(int i, String s) {
                Toast.show("退出登录失败");
            }

            @Override
            public void onException(Exception e) {
                Toast.show("退出登录失败");
            }
        });
    }

    public void login(View view) {
        UserKit.login(this, handler);
    }

    public void information(View view) {
        UserKit.information(this, handler);
    }

    public void register(View view) {
        UserKit.register(this, handler);
    }

    public void forgotPassword(View view) {
        UserKit.forgotPassword(this, handler);
    }

    public void modifyUsername(View view) {
        UserKit.modifyUserName(this, handler);
    }

    public void modifyPassword(View view) {
        UserKit.modifyPassword(this, handler);
    }
}
